<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>忘记密码</title>
    <link href="../css/register.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" charset="utf-8" src="../js/base/jquery.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/base/layer.js"></script>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon" rel="bookmark"/>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon" rel="icon"/>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon"
          rel="shortcut icon"/>
</head>
<body>
<div id="header">
    <a href="../index.html" class="spark" target='_blank'></a>
</div>
<div id="container">
    <div class="register-box">
        <h2>请设置您的新密码</h2>
        <table>
            <tr>
                <td style="width:145px;display:inline-block;vertical-align:middle">
                    <input id="telephone" placeholder="手机号码" style="width:115px;" oncut="return false;">
                </td>
                <td style="width:80px; display:inline-block;vertical-align:middle">
                    <input class="send-code-gray" onclick="settime(this)" value="获取验证码" style="width:80px;">
                </td>

            </tr>
            <tr>
                <td><input id="code" class="code" maxlength="4" placeholder="验证码" oncut="return false;"></td>
            </tr>
            <tr>
                <td>
                    <input type="password" id="password" placeholder="请输入6~16位密码" oncut="return false;" maxlength="16">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="password" id="password1" oncut="return false;" placeholder="请再次输入密码" maxlength="16">
                </td>
            </tr>
            <tr>
                <td style="height:30px;width:200px;text-align:center">
                    <a class="blue-big-button-gray" id="register-btn">保存</a>
                </td>
            </tr>
        </table>
    </div>
</div>
</body>
<script>
    var countdown = 60;
    var url_link = "http://118.178.59.93:8080/Motocycle/api/v1/";
    window.onload = function () {
        //发送验证码
        $('.send-code-gray').click(function () {
            var code_button = $(this)
            var tel_info = $('#telephone').val();
            var tel_preg = /^1[34578]\d{9}$/;
            if (tel_info == '') {
                layer.msg('请填写您的手机号!');
            } else if (!(tel_preg.test(tel_info))) {
                layer.msg('您的手机号填写有误!');
            } else {
                $.get(url_link + "verfications/" + tel_info, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code != 0) {
                        layer.msg('请稍后再发送!');
                    }
                })
            }

        });

        //忘记密码
        $('#register-btn').click(function () {
            var tel_info = $('#telephone').val();
            var code_info = $('#code').val();
            var pwd_info = $('#password').val();
            var pwd_info_1 = $('#password1').val();
            var tel_preg = /^1[34578]\d{9}$/;
            var psd_preg = /^[a-zA-Z0-9_-]{6,16}$/;
            if (tel_info == '') {
                layer.msg('请填写您的手机号!');
            } else if (!(tel_preg.test(tel_info))) {
                layer.msg('您的手机号填写有误!');
            } else if (code_info == '') {
                layer.msg('请填写您的验证码!');
            } else if (pwd_info == '') {
                layer.msg('请填写您的密码!');
            } else if (pwd_info_1 == '') {
                layer.msg('请再次填写您的密码!');
            } else if (!(psd_preg.test(pwd_info))) {
                layer.msg('您的密码格式填写有误!');
            } else if (pwd_info != pwd_info_1) {
                layer.msg('您两次填写的密码不同!');
            } else {
                $.get(url_link + "users/findPassword", {
                    mobile: tel_info,
                    password: pwd_info,
                    vercode: code_info
                }, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.code == 0) {
                        layer.msg("密码已重置,请重新登录!跳转中...");
                        setTimeout(function () {
                            window.location.href = "loading.html";
                        }, 3000)
                    }
                })

            }
        });
    };
    function settime(obj) {
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.value = "获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.value = "重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function () {
            settime(obj)
        }, 1000)
    }
</script>
</html>